package com.emar.adx.yiqifa.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import java.io.IOException;

public final class SpringUtil
{
	private static ApplicationContext fsxac = null;

	public static void init(String xmlFile) throws BeansException, IOException
	{
		//fsxac = new ClassPathXmlApplicationContext(xmlFile);
		//String separator = System.getProperty("file.separator");
		//System.out.println(System.getProperty("user.dir"));
		//System.out.println(xmlFile);
		fsxac = new FileSystemXmlApplicationContext(xmlFile);
		//fsxac = new FileSystemXmlApplicationContext(FilePathUtil.getAbsolutePath(xmlFile));
		//fsxac = new FileSystemXmlApplicationContext(System.getProperty("user.dir")+separator+"config"+separator+xmlFile);
	}

	public static Object getObject(String beanId) throws BeansException
	{
		Object obj = null;
		obj = fsxac.getBean(beanId);
	//	System.out.println(beanId);
		return obj;
	}

	public static Object getObject(String beanId, Class<?> className) throws BeansException
	{
		Object obj = null;
		obj = fsxac.getBean(beanId, className);
		return obj;
	}

    public static void main(String[] args) {

        try {
            SpringUtil.init("t.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
